package client;
import java.applet.Applet;
import java.awt.*;

import server.Cijferlijst;


/**
 * 
 * @author Jesse Gorter
 * 
 *
 */
public class MyApplet extends Applet 
{	
	public MyLoginCard logc;
	public MyListCard listc;
	public Panel north;
	public MyPanel south;
	
	public int port = 334;
	private MyPanel south2 = new MyPanel(false,this);
	
	public MyApplet()
	{	
		System.out.println(getClass().getProtectionDomain());
		this.setLayout(new BorderLayout());
		north = new Panel();
		north.add(new Label("Welcome"));
		this.setPreferredSize(new Dimension(600,600));
		
		south = new MyPanel(true, this);
		//south = new MyPanel(false,this);
		this.add(south, BorderLayout.SOUTH);
		
		logc = new MyLoginCard(this);
		//listc = new MyListCard();
		this.add(logc, BorderLayout.CENTER);
		//this.add(listc, BorderLayout.CENTER);
		this.add(north, BorderLayout.NORTH);
		
	}
	
	public void start()
	{
		
	}
	public void stop()
	{
		
	}
	public void destroy()
	{
		listc.deleteObserver();
	}
	public void paint()
	{
		
	}
	public void update()
	{
		
	}
	
	public void setText(String s)
	{
		this.remove(north);
		north = new Panel();
		north.add(new Label(s));
		this.add(north, BorderLayout.NORTH);
		this.repaint();
		this.validate();
		
	}
	
	public void changeSelectedCijfer(MyList list)
	{	
		String[] selected = (String[])listc.cijferlist.get(list.getSelectedIndex());
		south.f1.setText(selected[0]);
		south.f2.setText(selected[1]);
	}
	
	public void loadCijferlijst(Cijferlijst rem)
	{
		if(rem != null)
		{
			//load listcard
			this.remove(north);
			north = new Panel();
			north.add(new Label("TBL_STUDENTEN"));
			this.add(north, BorderLayout.NORTH);
			
			this.remove(south);
			south = south2;
			this.add(south, BorderLayout.SOUTH);
			
			this.remove(logc);
			listc = new MyListCard(rem, this);
			this.add(listc, BorderLayout.CENTER);
			
			this.repaint();
			this.validate();
		}
	}
}
